

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.StringTokenizer;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.JTable;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JScrollPane;
import javax.swing.table.DefaultTableModel;

import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JTextArea;
import javax.swing.UIManager;
import javax.swing.border.EtchedBorder;


public class EmpModifyPanel extends JPanel 
{
	public static Vector<MemberBean> vec = new Vector<MemberBean>();
	
	private JSplitPane splitPane;
	private JButton btnNewButton;
	private JButton btnNewButton_1;
	private JPanel panel;
	private JLabel lblNewLabel;
	private JPanel panel_1;
	private JPanel panel_2;
	private JPanel panel_3;
	private JButton btnEmpModify;
	private JButton btnEmpInput;
	private JButton btnEmpSearch;
	private JTextField tfFn;
	private JTextField tfLn;
	private JTextField tfDeptID;
	private JTextField tfJobID;
	private JTextField tfEmail;
	private JTextField tfPnum;
	private JTextField tfMngId;
	private JTextField tfHD;
	private JTextField tfSearchZip;
	private JButton EmpPostSearchbtn;
	private JLabel lblNewLabel_12;
	private JTextField tfZip;
	private JLabel lblNewLabel_13;
	private JComboBox comboBox;
	private JTextField tfFirstName;
	private JTextField tfLastName;
	private JLabel lblLastName;
	private JLabel lblFirstName;
	private JButton EmpSearchButton;
	private JScrollPane scrollPane;
	private JTable table;

	private String selCon="name";
	private String selected = "";
	
	private int selId = 0;
	
	private Connection conn;
	private Vector<MemberBean> v = null;
	
	private int index;
	
	DefaultTableModel model;
	private JTextField tfdetailAdd;
	private JScrollPane scrollPane_1;
	private JList list;
	private JLabel label;
	private JLabel label_1;
	private JLabel label_2;
	private JLabel label_3;
	private JLabel label_4;
	private JLabel label_5;
	private JLabel label_6;
	private JLabel label_7;
	private JLabel label_8;
	private JLabel label_9;
	private JLabel label_10;
	private JLabel lblID;
	
	private void connect() throws SQLException, ClassNotFoundException
	{
		conn = DBconn.getConnection();
	}
	
	private void close() throws SQLException
	{
		DBconn.close();
		conn = null;
	}
	
	/**
	 * Create the panel.
	 */
	public EmpModifyPanel() 
	{
		setBackground(new Color(173, 216, 230));
		setLayout(new BorderLayout(0, 0));
		add(getSplitPane(), BorderLayout.SOUTH);
		add(getPanel(), BorderLayout.NORTH);
		add(getPanel_1(), BorderLayout.WEST);
		add(getPanel_2(), BorderLayout.CENTER);

		MemberBean mem;
		try 
		{
			connect();
			
			String sql = "select e.employee_id, e.first_name, e.last_name, e.email, "
					+ " e.phone_number, e.hire_date, e.job_id, e.manager_id, d.department_name, "
					+ " e.department_id, e.zipcode, e.address from emp e, departments d where e.department_id=d.department_id";
			
			PreparedStatement pstmt = conn.prepareStatement(sql);
			ResultSet rs = pstmt.executeQuery();
			
			
			
			while (rs.next()) 
			{
				mem = new MemberBean();
				mem.setEmpId(rs.getInt("employee_id"));
				mem.setFirName(rs.getString("first_name"));
				mem.setLastName(rs.getString("last_name"));
				mem.setEmail(rs.getString("email"));
				mem.setpNum(rs.getString("phone_number"));
				mem.sethDate(rs.getDate("hire_date"));
				mem.setJobId(rs.getString("job_id"));
				mem.setMngId(rs.getInt("manager_id"));
				mem.setDeptName(rs.getString("department_name"));
				mem.setDeptId(rs.getInt("department_id"));
				mem.setZipcode(rs.getString("zipcode"));
				mem.setAddr(rs.getString("address"));
				
				vec.add(mem);
			}
			System.out.println(vec.size());
		} 
		catch (ClassNotFoundException | SQLException e) 
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	private JSplitPane getSplitPane() 
	{
		if (splitPane == null) 
		{
			splitPane = new JSplitPane();
			splitPane.setBackground(new Color(245, 255, 250));
			splitPane.setRightComponent(getBtnNewButton());
			splitPane.setLeftComponent(getBtnNewButton_1());
		}
		return splitPane;
	}
	
	private JButton getBtnNewButton() 
	{
		if (btnNewButton == null) 
		{
			btnNewButton = new JButton(); //$NON-NLS-1$
			btnNewButton.setBackground(UIManager.getColor("Button.light"));
			btnNewButton.setText("수정");
			btnNewButton.addActionListener(new ActionListener() 
			{
				public void actionPerformed(ActionEvent arg0) 
				{
					String jId = "";
					//String hd = "2013-01-01";
					
					int id = selId;
					String fn = tfFn.getText();
					String ln = tfLn.getText();
					String email = tfEmail.getText();
					String pN = tfPnum.getText();
					String zip = tfZip.getText();
					String detail = tfdetailAdd.getText();
					int deptId  = Integer.parseInt(tfDeptID.getText());
					String hd = tfHD.getText();
					
					jId += tfJobID.getText();
					
					int mngid = Integer.parseInt(tfMngId.getText());
					
					if (!tfHD.getText().trim().equals("")) 
					{
						hd = tfHD.getText();
					}
					
					System.out.println("id : "+id);
					
					int i = 4;

					try 
					{
						connect();

						String sql = "update emp set first_name = ?, LAST_NAME = ?, DEPARTMENT_ID =?, JOB_ID = ?, EMAIL = ?, PHONE_NUMBER =?, MANAGER_ID = ?, zipcode = ?, address=? where employee_id = ?";
						PreparedStatement pstmt = conn.prepareStatement(sql);
						
						pstmt.setString(1,fn);
						pstmt.setString(2, ln);
						pstmt.setInt(3, deptId);
						pstmt.setString(4, jId);
						pstmt.setString(5, email);
						pstmt.setString(6, pN);
						pstmt.setInt(7, mngid);
						pstmt.setString(8, zip);
						pstmt.setString(9, detail);
						pstmt.setInt(10, id);

						pstmt.executeUpdate();
						
						
						
						pstmt.close();
						close();
						//===========================
						date(hd, id);
						//==========================
						tfFn.setText("");
						tfLn.setText("");
						tfEmail.setText("");
						tfPnum.setText("");
						tfZip.setText("");
						tfdetailAdd.setText("");
						tfDeptID.setText("");
						tfHD.setText("");
						tfJobID.setText("");
						tfMngId.setText("");

					} 
					catch (Exception e) 
					{
						e.printStackTrace();
					}
				}
			});
		}
		return btnNewButton;
	}
	
	void date(String date, int id)
	{
		try 
		{
			connect();
			
			String sql = "update emp set hire_date = ? where employee_id = ? "; 
			
			PreparedStatement pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, date);
			pstmt.setInt(2, id);
			
			pstmt.executeUpdate();
			
			pstmt.close();
			close();	
		} 
		catch (ClassNotFoundException | SQLException e) 
		{
			e.printStackTrace();
		}
	}
	
	private JButton getBtnNewButton_1() 
	{
		if (btnNewButton_1 == null) 
		{
			btnNewButton_1 = new JButton(); //$NON-NLS-1$
			btnNewButton_1.setBackground(UIManager.getColor("Button.light"));
			btnNewButton_1.setText("삭제");
			btnNewButton_1.setMinimumSize(new Dimension(120, 23));
			btnNewButton_1.setMaximumSize(new Dimension(120, 23));
			btnNewButton_1.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					empDelete();
					search();
				}
			});
		}
		return btnNewButton_1;
	}
	private JPanel getPanel() 
	{
		if (panel == null) 
		{
			panel = new JPanel();
			panel.setBackground(new Color(245, 255, 250));
			panel.setPreferredSize(new Dimension(10, 34));
			panel.setLayout(new BorderLayout(0, 0));
			panel.add(getLabel_1(), BorderLayout.WEST);
			panel.add(getPanel_3(), BorderLayout.CENTER);
		}
		return panel;
	}
	private JLabel getLabel_1() 
	{
		if (lblNewLabel == null) 
		{
			lblNewLabel = new JLabel("수정 & 삭제"); //$NON-NLS-1$
			lblNewLabel.setForeground(new Color(0, 0, 0));
			lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
			lblNewLabel.setFont(new Font("돋움", Font.BOLD, 17));
			lblNewLabel.setPreferredSize(new Dimension(120, 15));
		}
		return lblNewLabel;
	}
	private JPanel getPanel_1() 
	{
		if (panel_1 == null) 
		{
			panel_1 = new JPanel();
			panel_1.setBackground(new Color(245, 255, 250));
			panel_1.setPreferredSize(new Dimension(120, 10));
			panel_1.setMinimumSize(new Dimension(30, 30));
			panel_1.setLayout(null);
			panel_1.add(getLblNewLabel_13());
			panel_1.add(getLabel_11());
			panel_1.add(getLabel_1_2());
			panel_1.add(getLabel_2_1());
			panel_1.add(getLabel_3_1());
			panel_1.add(getLabel_4_1());
		}
		return panel_1;
	}
	
	private JPanel getPanel_2() 
	{
		if (panel_2 == null) 
		{
			panel_2 = new JPanel();
			panel_2.setBackground(new Color(245, 255, 250));
			panel_2.setLayout(null);
			panel_2.add(getTfFn());
			panel_2.add(getTfLn());
			panel_2.add(getTfDeptID());
			panel_2.add(getTfJobID());
			panel_2.add(getTfEmail());
			panel_2.add(getTfPnum());
			panel_2.add(getTfMngId());
			panel_2.add(getTfHD());
			panel_2.add(getTfSearchZip());
			panel_2.add(getEmpPostSearchbtn());
			panel_2.add(getLblNewLabel_12());
			panel_2.add(getTfZip());
			panel_2.add(getComboBox());
			panel_2.add(getTfFirstName());
			panel_2.add(getTfLastName());
			panel_2.add(getLblLastName());
			panel_2.add(getLabel_1_1());
			panel_2.add(getEmpSearchButton());
			panel_2.add(getScrollPane());
			panel_2.add(getTfdetailAdd());
			panel_2.add(getScrollPane_1());
			panel_2.add(getLabel_5_1());
			panel_2.add(getLabel_6_1());
			panel_2.add(getLabel_7_1());
			panel_2.add(getLabel_8_1());
			panel_2.add(getLabel_9_1());
			panel_2.add(getLabel_10_1());
			panel_2.add(getLabel_11_1());
		}
		return panel_2;
	}
	
	private JPanel getPanel_3() 
	{
		if (panel_3 == null) 
		{
			panel_3 = new JPanel();
			panel_3.setLayout(new BorderLayout(0, 0));
			panel_3.add(getBtnEmpModify(), BorderLayout.EAST);
			panel_3.add(getBtnEmpInput(), BorderLayout.CENTER);
			panel_3.add(getBtnEmpSearch(), BorderLayout.WEST);
		}
		return panel_3;
	}
	
	private JButton getBtnEmpModify() 
	{
		if (btnEmpModify == null) 
		{
			btnEmpModify = new JButton(); //$NON-NLS-1$
			btnEmpModify.setMinimumSize(new Dimension(160, 9));
			btnEmpModify.setMaximumSize(new Dimension(160, 9));
			btnEmpModify.setPreferredSize(new Dimension(160, 9));
			btnEmpModify.setForeground(new Color(255, 255, 255));
			btnEmpModify.setFont(new Font("Dialog", Font.BOLD, 17));
			btnEmpModify.setBackground(new Color(135, 206, 250));
			btnEmpModify.setText("수정 & 삭제");
		}
		return btnEmpModify;
	}
	
	private JButton getBtnEmpInput() 
	{
		if (btnEmpInput == null) 
		{
			btnEmpInput = new JButton(); //$NON-NLS-1$
			btnEmpInput.setForeground(new Color(255, 255, 255));
			btnEmpInput.setFont(new Font("Dialog", Font.BOLD, 17));
			btnEmpInput.setBackground(new Color(135, 206, 250));
			btnEmpInput.setText("사원 등록");
			btnEmpInput.setMinimumSize(new Dimension(120, 23));
			btnEmpInput.setMaximumSize(new Dimension(120, 23));
			btnEmpInput.setPreferredSize(new Dimension(120, 23));
		}
		return btnEmpInput;
	}
	private JButton getBtnEmpSearch() 
	{
		if (btnEmpSearch == null) 
		{
			btnEmpSearch = new JButton(); //$NON-NLS-1$
			btnEmpSearch.setForeground(new Color(255, 255, 255));
			btnEmpSearch.setFont(new Font("Dialog", Font.BOLD, 17));
			btnEmpSearch.setBackground(new Color(135, 206, 250));
			btnEmpSearch.setText("사원 조회");
			btnEmpSearch.setPreferredSize(new Dimension(160, 23));
			btnEmpSearch.setMinimumSize(new Dimension(120, 23));
			btnEmpSearch.setMaximumSize(new Dimension(120, 23));
		}
		return btnEmpSearch;
	}
	
	private JTextField getTfFn() 
	{
		if (tfFn == null) 
		{
			tfFn = new JTextField("");
			tfFn.setBounds(12, 142, 116, 21);
			tfFn.setColumns(10);
		}
		return tfFn;
	}
	
	private JTextField getTfLn() {
		if (tfLn == null) {
			tfLn = new JTextField("");
			tfLn.setBounds(12, 173, 116, 21);
			tfLn.setColumns(10);
		}
		return tfLn;
	}
	private JTextField getTfDeptID() {
		if (tfDeptID == null) {
			tfDeptID = new JTextField("");
			tfDeptID.setBounds(12, 204, 116, 21);
			tfDeptID.setColumns(10);
		}
		return tfDeptID;
	}
	private JTextField getTfJobID() {
		if (tfJobID == null) {
			tfJobID = new JTextField("");
			tfJobID.setBounds(12, 235, 116, 21);
			tfJobID.setColumns(10);
		}
		return tfJobID;
	}
	private JTextField getTfEmail() {
		if (tfEmail == null) {
			tfEmail = new JTextField("");
			tfEmail.setBounds(273, 142, 216, 21);
			tfEmail.setColumns(10);
		}
		return tfEmail;
	}
	private JTextField getTfPnum() {
		if (tfPnum == null) {
			tfPnum = new JTextField("");
			tfPnum.setBounds(273, 173, 216, 21);
			tfPnum.setColumns(10);
		}
		return tfPnum;
	}
	private JTextField getTfMngId() {
		if (tfMngId == null) {
			tfMngId = new JTextField("");
			tfMngId.setBounds(273, 204, 216, 21);
			tfMngId.setColumns(10);
		}
		return tfMngId;
	}
	private JTextField getTfHD() {
		if (tfHD == null) {
			tfHD = new JTextField("");
			tfHD.setBounds(273, 235, 216, 21);
			tfHD.setColumns(10);
		}
		return tfHD;
	}
	private JTextField getTfSearchZip() 
	{
		if (tfSearchZip == null) 
		{
			tfSearchZip = new JTextField("");
			tfSearchZip.setBounds(72, 270, 145, 21);
			tfSearchZip.addKeyListener(new KeyAdapter() 
			{
				@Override
				public void keyPressed(KeyEvent key) 
				{
					if (key.getKeyCode()==KeyEvent.VK_ENTER) 
					{
						addrSearch();
					}
				}
			});
			tfSearchZip.setColumns(10);
		}
		return tfSearchZip;
	}
	
	private JButton getEmpPostSearchbtn() 
	{
		if (EmpPostSearchbtn == null) 
		{
			EmpPostSearchbtn = new JButton();
			EmpPostSearchbtn.setBackground(UIManager.getColor("Button.light"));
			EmpPostSearchbtn.setText("우편번호 검색");
			EmpPostSearchbtn.setBounds(228, 269, 132, 23);
			EmpPostSearchbtn.addActionListener(new ActionListener() 
			{
				public void actionPerformed(ActionEvent arg0) 
				{
					addrSearch();
				}
			});
		}
		return EmpPostSearchbtn;
	}
	
	private JLabel getLblNewLabel_12() {
		if (lblNewLabel_12 == null) {
			lblNewLabel_12 = new JLabel("동읍면 :");
			lblNewLabel_12.setBounds(12, 273, 57, 15);
		}
		return lblNewLabel_12;
	}
	private JTextField getTfZip() {
		if (tfZip == null) {
			tfZip = new JTextField("");
			tfZip.setBounds(72, 298, 195, 21);
			tfZip.setColumns(10);
		}
		return tfZip;
	}
	private JLabel getLblNewLabel_13() {
		if (lblNewLabel_13 == null) {
			lblNewLabel_13 = new JLabel("조회 사원의 ");
			lblNewLabel_13.setFont(new Font("굴림", Font.BOLD, 15));
			lblNewLabel_13.setBounds(31, 12, 87, 22);
		}
		return lblNewLabel_13;
	}
	private JComboBox getComboBox() 
	{
		if (comboBox == null) 
		{
			comboBox = new JComboBox();
			comboBox.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, new Color(70, 130, 180)));
			comboBox.setBackground(UIManager.getColor("Button.light"));
			comboBox.setBounds(12, 10, 88, 27);
			comboBox.addActionListener(new ActionListener() 
			{
				public void actionPerformed(ActionEvent comBox) 
				{
					String selectModel = comboBox.getSelectedItem().toString();
					
					if (selectModel.trim().equals("ID")) 
					{
						lblFirstName.setText("");
						lblFirstName.setText("ID :");
						lblLastName.setVisible(false);
						tfLastName.setVisible(false);
						tfFirstName.setText("");
					}
					else
					{
						lblFirstName.setText("");
						lblFirstName.setText("First : ");
						lblLastName.setVisible(true);
						tfLastName.setVisible(true);
						tfFirstName.setText("");
					}
					
					JComboBox<String> jcb = (JComboBox<String>)comBox.getSource();
					
					if (jcb.getSelectedItem().equals("ID")) 
					{
						selCon = "id";
					}
					if (jcb.getSelectedItem().equals("Name")) 
					{
						selCon = "name";
					}
				}
			});
			comboBox.setModel(new DefaultComboBoxModel(new String[] {"Name", "ID"}));
		}
		return comboBox;
	}
	
	private JTextField getTfFirstName() 
	{
		if (tfFirstName == null) 
		{
			tfFirstName = new JTextField("");
			tfFirstName.setBounds(162, 10, 72, 27);
			tfFirstName.addKeyListener(new KeyAdapter() 
			{
				@Override
				public void keyPressed(KeyEvent key)
				{
					if (key.getKeyCode() == KeyEvent.VK_ENTER) 
					{
						search();
					}
				}
			});
			tfFirstName.setColumns(10);
		}
		return tfFirstName;
	}
	
	private JTextField getTfLastName() 
	{
		if (tfLastName == null) 
		{
			tfLastName = new JTextField("");
			tfLastName.setBounds(293, 10, 62, 27);
			tfLastName.addKeyListener(new KeyAdapter()
			{
				@Override
				public void keyPressed(KeyEvent key)
				{
					if (key.getKeyCode()==KeyEvent.VK_ENTER) 
					{
						search();
					}
				}
			});
			tfLastName.setColumns(10);
		}
		return tfLastName;
	}
	private JLabel getLblLastName() 
	{
		if (lblLastName == null) 
		{
			lblLastName = new JLabel("Last :");
			lblLastName.setBounds(246, 10, 55, 27);
		}
		return lblLastName;
	}
	
	private JLabel getLabel_1_1() 
	{
		if (lblFirstName == null) 
		{
			lblFirstName = new JLabel("First :");
			lblFirstName.setBounds(123, 10, 48, 27);
		}
		return lblFirstName;
	}
	
	private JButton getEmpSearchButton() 
	{
		if (EmpSearchButton == null) 
		{
			EmpSearchButton = new JButton("Search");
			EmpSearchButton.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, new Color(70, 130, 180)));
			EmpSearchButton.setBackground(UIManager.getColor("Button.light"));
			EmpSearchButton.setBounds(397, 10, 79, 27);
			EmpSearchButton.addActionListener(new ActionListener() 
			{
				public void actionPerformed(ActionEvent arg0) 
				{
					search();
				}
			});
		}
		return EmpSearchButton;
	}
	
	private JScrollPane getScrollPane() 
	{
		if (scrollPane == null) 
		{
			scrollPane = new JScrollPane();
			scrollPane.setBounds(12, 46, 482, 65);
			scrollPane.setViewportView(getTable());
		}
		return scrollPane;
	}
	
	private JTable getTable() 
	{
		if (table == null)
		{
			table = new JTable();
			table.addMouseListener(new MouseAdapter() 
			{
				@Override
				public void mouseClicked(MouseEvent arg0) 
				{
					Object value = table.getValueAt(table.getSelectedRow(), 0);
					
					selId = (Integer)value;
					
					System.out.println("v mouse : " + selId);

					lblID.setText(Integer.toString(selId));
					
					search();
				}
			});
		}
		return table;
	}
	
	private JTextField getTfdetailAdd() {
		if (tfdetailAdd == null) {
			tfdetailAdd = new JTextField("");
			tfdetailAdd.setBounds(273, 298, 216, 21);
			tfdetailAdd.setText("");
			tfdetailAdd.setColumns(10);
		}
		return tfdetailAdd;
	}
	
	
	void search()
	{
		try 
		{
			model = new DefaultTableModel();
			model.setColumnIdentifiers(new String[]{"ID", "First Name", "Last Name","Department Name", "Email", "Phone Number", "Manager ID"});
	
			//===============================================================================			

			connect();
			
			String sql = "select e.employee_id, e.first_name, e.last_name, d.department_name, e.department_id, e.email, e.phone_number, e.manager_id from emp e, departments d where e.department_id=d.department_id and ";
			
			if (selCon.equals("id")) 
			{
				sql+= " employee_id = ?";
			}
			if (selCon.equals("name")) 
			{
				if (tfFirstName.getText().trim().equals("")&&!tfLastName.getText().trim().equals("")) 
				{
					sql+=" last_name like ? ";
					selected = "onlyLn";
				}
				
				if (tfFirstName.getText().trim().equals("")&&tfLastName.getText().trim().equals("")) 
				{
					JOptionPane.showMessageDialog(null, "검색할 이름을 입력해주십시오", "Error", JOptionPane.ERROR_MESSAGE);
					return;
				}

				if (!tfFirstName.getText().trim().equals("")&&tfLastName.getText().trim().equals("")) 
				{
					sql+=" first_name like ? ";
					selected = "onlyFn";
				}

				if (!tfFirstName.getText().trim().equals("")&&!tfLastName.getText().trim().equals("")) 
				{
					sql+=" first_name like ? and last_name like ? ";
					selected = "Fnln";
				}

			}
			
			PreparedStatement pstmt = conn.prepareStatement(sql);
			
			if (selCon.equals("id")) 
			{
				pstmt.setInt(1, Integer.parseInt(tfFirstName.getText()));
			}
			else if(selected.equals("onlyFn"))
			{
				pstmt.setString(1, "%"+tfFirstName.getText()+"%");
			}
			else if(selected.equals("onlyLn"))
			{
				pstmt.setString(1,"%"+tfLastName.getText()+"%" );
			}
			else if (selected.equals("Fnln")) 
			{
				pstmt.setString(1, "%"+tfFirstName.getText()+"%");
				pstmt.setString(2, "%"+tfLastName.getText()+"%" );
			}

			ResultSet rs = pstmt.executeQuery();

			v = new Vector<MemberBean>();
			
			MemberBean bean;
			
			while (rs.next()) 
			{
				bean = new MemberBean();
				bean.setEmpId(rs.getInt("employee_id"));
				bean.setFirName(rs.getString("first_name"));
				bean.setLastName(rs.getString("last_name"));
				bean.setDeptId(rs.getInt("department_id"));
				bean.setDeptName(rs.getString("department_name"));
				bean.setEmail(rs.getString("email"));
				bean.setpNum(rs.getString("phone_number"));
				bean.setMngId(rs.getInt("manager_id"));
				v.add(bean);
			}
		
			int size = v.size();
			
			
			for (MemberBean m : v) 
			{
				model.addRow(new Object[]{m.getEmpId(), m.getFirName(), m.getLastName(), m.getDeptName(), m.getEmail(), m.getpNum(), m.getMngId()});
			}
			
			System.out.println(v.size());
			

			
			System.out.println("label : "+label.getText());
			
			int index=0;
			selId=0;
			
			if (!lblID.getText().equals("")) 
			{
				selId = Integer.parseInt(lblID.getText());
			}
		
			for (MemberBean mb : vec) 
			{
				if(selId!=0&&mb.getEmpId()==selId)
				{
					tfFn.setText(mb.getFirName());
					tfLn.setText(mb.getLastName());
					tfEmail.setText(mb.getEmail());
					tfPnum.setText(mb.getpNum());
					tfZip.setText(mb.getZipcode());
					tfdetailAdd.setText(mb.getAddr());
					tfDeptID.setText(Integer.toString(mb.getDeptId()));
					tfHD.setText(mb.gethDate().toString());
					tfJobID.setText(mb.getJobId());
					tfMngId.setText(Integer.toString(mb.getMngId()));

				}
				
			}
		
			lblID.setText("");
			
			rs.close();
			pstmt.close();
			close();
		} 
		catch (Exception e) 
		{
			e.printStackTrace();
		}
		
		//============================================================================

		table.setModel(model);
	}
	
	
	
	void addrSearch() 
	{
		try 
		{
			connect();
			
			String dong = tfSearchZip.getText();
			
			Vector<ZipCode> vector = new Vector<ZipCode>();
			
			String sql = "select * from zipcode where dong like ?";
			
			PreparedStatement pstmt = conn.prepareStatement(sql);
			
			if (dong.equals("")) 
			{
				JOptionPane.showMessageDialog(null, "검색할 동읍면을 입력해주십시오", "Error", JOptionPane.ERROR_MESSAGE);
				return;
			}
			if (!dong.equals(""))
			{
				pstmt.setString(1, "%"+dong+"%");
			}
			
			ResultSet rs = pstmt.executeQuery();
			
			while (rs.next()) 
			{
				ZipCode zc = new ZipCode();
				zc.setZipcode(rs.getString("zipcode"));
				zc.setSido(rs.getString("sido"));
				zc.setGugun(rs.getString("gugun"));
				zc.setDong(rs.getString("dong"));
				
				if (rs.getString("bunji") == null) 
				{
					zc.setBunji("");
				}
				else
				{
					zc.setBunji(rs.getString("bunji"));
				}
				
				if (rs.getString("ri") == null) 
				{
					zc.setRi("");
				}
				else
				{
					zc.setRi(rs.getString("ri"));
				}
				
				if (rs.getString("bld_name") == null) 
				{
					zc.setBld_name("");
				}
				else
				{
					zc.setBld_name(rs.getString("bld_name"));
				}
				
				vector.add(zc);			
			}
			
			list.setListData(vector);
		} 
		catch (ClassNotFoundException | SQLException e) 
		{
			e.printStackTrace();
		}
		
		
	}
	private JScrollPane getScrollPane_1() {
		if (scrollPane_1 == null) {
			scrollPane_1 = new JScrollPane();
			scrollPane_1.setBounds(12, 326, 482, 53);
			scrollPane_1.setViewportView(getList());
		}
		return scrollPane_1;
	}
	private JList getList() 
	{
		if (list == null) 
		{
			list = new JList();
			list.addMouseListener(new MouseAdapter() 
			{
				@Override
				public void mouseClicked(MouseEvent arg0) 
				{
					System.out.println(list.getSelectedValue());
					ZipCode zip = (ZipCode) list.getSelectedValue();
					
					tfZip.setText(zip.toString());
				}
			});
		}
		return list;
	}
	private JLabel getLabel_11() {
		if (label == null) {
			label = new JLabel();
			label.setFont(new Font("굴림", Font.BOLD, 14));
			label.setText(" * 필수입력 *");
			label.setBounds(12, 117, 96, 15);
		}
		return label;
	}
	private JLabel getLabel_1_2() {
		if (label_1 == null) {
			label_1 = new JLabel();
			label_1.setText("First Name : ");
			label_1.setBounds(10, 146, 96, 15);
		}
		return label_1;
	}
	private JLabel getLabel_2_1() {
		if (label_2 == null) {
			label_2 = new JLabel();
			label_2.setText("Last name :");
			label_2.setBounds(11, 177, 96, 15);
		}
		return label_2;
	}
	private JLabel getLabel_3_1() {
		if (label_3 == null) {
			label_3 = new JLabel();
			label_3.setText("Department ID :");
			label_3.setBounds(12, 208, 96, 15);
		}
		return label_3;
	}
	private JLabel getLabel_4_1() {
		if (label_4 == null) {
			label_4 = new JLabel();
			label_4.setText("Job ID :");
			label_4.setBounds(12, 241, 96, 15);
		}
		return label_4;
	}
	private JLabel getLabel_5_1() {
		if (label_5 == null) {
			label_5 = new JLabel();
			label_5.setFont(new Font("굴림", Font.BOLD, 14));
			label_5.setText("* 선택입력 *");
			label_5.setBounds(185, 115, 96, 15);
		}
		return label_5;
	}
	private JLabel getLabel_6_1() {
		if (label_6 == null) {
			label_6 = new JLabel();
			label_6.setText("E-mail :");
			label_6.setBounds(207, 145, 62, 15);
		}
		return label_6;
	}
	private JLabel getLabel_7_1() {
		if (label_7 == null) {
			label_7 = new JLabel();
			label_7.setText("Phone Number :");
			label_7.setBounds(161, 176, 96, 15);
		}
		return label_7;
	}
	private JLabel getLabel_8_1() {
		if (label_8 == null) {
			label_8 = new JLabel();
			label_8.setText("Manager ID :");
			label_8.setBounds(183, 207, 86, 15);
		}
		return label_8;
	}
	private JLabel getLabel_9_1() {
		if (label_9 == null) {
			label_9 = new JLabel();
			label_9.setText("Hire Date :");
			label_9.setBounds(197, 238, 72, 15);
		}
		return label_9;
	}
	private JLabel getLabel_10_1() {
		if (label_10 == null) {
			label_10 = new JLabel();
			label_10.setText("상세주소 :");
			label_10.setBounds(12, 301, 72, 15);
		}
		return label_10;
	}
	private JLabel getLabel_11_1() {
		if (lblID == null) {
			lblID = new JLabel("");
			lblID.setBounds(12, 117, 57, 15);
		}
		return lblID;
	}
	
	private void empDelete() {
		try {
			connect();
			
			// 삭제 쿼리
			String qry = "DELETE FROM EMP WHERE EMPLOYEE_ID = " + selId;
			PreparedStatement pstmt = conn.prepareStatement(qry);
			pstmt.executeUpdate();
			
			pstmt.close();
			close();
			
			JOptionPane.showMessageDialog( this, "선택하신 사원이 삭제 되었습니다.", "사원 삭제", 
					JOptionPane.INFORMATION_MESSAGE);
			
			// 삭제 후 모든 텍스트 필드를 초기화 한다.
			tfFn.setText("");
			tfLn.setText("");
			tfDeptID.setText("");
			tfJobID.setText("");
			tfEmail.setText("");
			tfPnum.setText("");
			tfMngId.setText("");
			tfHD.setText("");
			tfSearchZip.setText("");
			tfZip.setText("");
			tfdetailAdd.setText("");
			list.removeAll();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
